﻿@using CnGalWebSite.Components.Services;
@inject NavigationManager NavigationManager
@inject ImagesLargeViewService ImagesLargeViewService
@inject IDataCacheService _dataCatcheService
@inject IEventService _eventService


<MDCard Class="gallery-card">
    <div class="content">
        <div class="head">
            <div class="name text-truncate-1 headline-large">@Model.Name</div>
            <div class="tags">
                @foreach (var item in Model.Tags.Random().Take(2))
                {
                    <CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.IconChip Icon="IconType.Tag" Text="@item" />
                }
            </div>

        </div>
        <div class="brief text-truncate-2 label-large">@Model.BriefIntroduction</div>
    </div>
    <div class="gallery">
        <CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.SlideGroup Items="Model.Images">
            <MImage Height="_dataCatcheService.IsApp?126: 180" Width="_dataCatcheService.IsApp?224: 320" Src="@context" @onclick="()=>OnClickImage(context)">
                <PlaceholderContent>
                    <MRow Class="fill-height ma-0"
                          Align="@AlignTypes.Center"
                          Justify="@JustifyTypes.Center">
                        <MProgressCircular Indeterminate Color="primary"></MProgressCircular>
                     </MRow>
                 </PlaceholderContent>
             </MImage>
         </CnGalWebSite.Shared.MasaComponent.PC.Home.Cards.Shared.SlideGroup>
     </div>
     <CnGalWebSite.Components.Containers.MiniModeContainer>
         <div class="actions">
             <CnGalWebSite.Components.Buttons.MasaButton Text="详情" TextStyle Rounded Icon="@IconType.Infor.ToIconString()" OnClick="@(()=>NavigationManager.NavigateTo($"/entries/index/{Model.Id}"))" />
             @if (_dataCatcheService.IsApp == false)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Buttons.FavoriteButton Type="FavoriteObjectType.Entry" Id="Model.Id" PlainText />
            }
            @if (string.IsNullOrWhiteSpace(Model.SteamId) == false)
            {
                <CnGalWebSite.Components.Buttons.MasaButton Rounded Text="Steam" Icon="@IconType.Steam.ToIconString()" OnClick="@(()=>_eventService.OpenNewPage($"https://store.steampowered.com/app/{Model.SteamId}"))" />
            }
        </div>
    </CnGalWebSite.Components.Containers.MiniModeContainer>
</MDCard>


@code {
    [Parameter]
    public PersonalRecommendModel Model { get; set; }

    public async Task OnClickImage(string image)
    {
        if (_dataCatcheService.IsApp)
        {
            await _eventService.OpenNewPage(image);
        }
        else
        {
            await ImagesLargeViewService.ViewLargeImages(Model.Images.Select(s => new ImagesLargeViewModel
                {
                    Image = s,
                }).ToList(), Model.Images.IndexOf(image));
        }

    }

}
